package io.renren.dictionary.controller;

import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.dictionary.entity.TDictionaryTypeEntity;
import io.renren.dictionary.service.TDictionaryTypeService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import io.renren.common.utils.R;




/**
 * 字典类型表
 * 
 * @author zhangyao
 * @email zhangyao@sdbeiluo.com
 * @date 2017-12-18 15:25:23
 */
@RestController
@RequestMapping("/dictionary/tdictionarytype")
public class TDictionaryTypeController {
	@Autowired
	private TDictionaryTypeService tDictionaryTypeService;
	
	/**
	 * 列表
	 */
	@RequestMapping("/list")
	@RequiresPermissions("dictionary:tdictionarytype:list")
	public R list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);

		List<TDictionaryTypeEntity> tDictionaryTypeList = tDictionaryTypeService.queryList(query);
		int total = tDictionaryTypeService.queryTotal(query);
		
		PageUtils pageUtil = new PageUtils(tDictionaryTypeList, total, query.getLimit(), query.getPage());
		
		return R.ok().put("page", pageUtil);
	}
	
	
	/**
	 * 信息
	 */
	@RequestMapping("/info/{id}")
	@RequiresPermissions("dictionary:tdictionarytype:info")
	public R info(@PathVariable("id") String id){
		TDictionaryTypeEntity tDictionaryType = tDictionaryTypeService.queryObject(id);
		
		return R.ok().put("tDictionaryType", tDictionaryType);
	}
	
	/**
	 * 保存
	 */
	@RequestMapping("/save")
	@RequiresPermissions("dictionary:tdictionarytype:save")
	public R save(@RequestBody TDictionaryTypeEntity tDictionaryType){
		tDictionaryTypeService.save(tDictionaryType);
		
		return R.ok();
	}
	
	/**
	 * 修改
	 */
	@RequestMapping("/update")
	@RequiresPermissions("dictionary:tdictionarytype:update")
	public R update(@RequestBody TDictionaryTypeEntity tDictionaryType){
		tDictionaryTypeService.update(tDictionaryType);
		
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@RequestMapping("/delete")
	@RequiresPermissions("dictionary:tdictionarytype:delete")
	public R delete(@RequestBody String[] ids){
		tDictionaryTypeService.deleteBatch(ids);
		
		return R.ok();
	}
	
}
